<?php
//No direct access
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');

class OwnserviceViewFees extends JView
{
	function display($tpl=null) {

		global $mainframe, $option;

		//Initialise variables
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$document	= & JFactory::getDocument();
		$db			= & JFactory::getDBO();
		$params 	= & $mainframe->getParams('com_ownservice');

		//get var
		$rate_id	= JRequest::getVar('rate_id', 0);
		$type		= JRequest::getVar('type', '');
		
		//check has rate ID ?
		if($rate_id <= 0)
		{
			$mainframe->redirect(JRoute::_('index.php?option=com_ownservice&view=exchangerates'), JText::_('OWN_NOT_EXCHANGE_RATE_ID'));
			return;
		}
		
		// Make sure you are logged in and have the necessary access rights
		if($user->gid < 25) {
			if (!Ownservice::checkAccess( 'fee', 'manage' )) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		$filter_order		= $mainframe->getUserStateFromRequest($option.'.fee.filter_order', 'filter_order', 'fee', 'cmd');
		$filter_order_Dir	= $mainframe->getUserStateFromRequest($option.'.fee.filter_order_Dir', 'filter_order_Dir', '', 'cmd');

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/icon.css');
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/ownservice.js');

		//Get data form the model
		$model		= $this->getModel();
		$rows		= & $this->get('Data');
		$rate		= $model->getExchangeRate($rate_id);

		// Create a user access object for the current user
		$access = new stdClass();
		$access->canView		= ($user->gid < 25)? Ownservice::checkAccess('fee','view','fee','all'):1;
		$access->canEdit		= ($user->gid < 25)? Ownservice::checkAccess('fee','edit','fee','all'):1;
		$access->canAdd			= ($user->gid < 25)? Ownservice::checkAccess('fee','add','fee','all'):1;
		$access->canDelete		= ($user->gid < 25)? Ownservice::checkAccess('fee','delete','fee','all'):1;

		$lists = array();

		$lists['order']     = $filter_order;
		$lists['order_Dir'] = $filter_order_Dir;

		//set page title
		$params->set('page_title',	JText::_('OWNSERVICE_FEE'));
		$document->setTitle( $params->get('page_title') );

		$this->assignRef('rows', $rows);
		$this->assignRef('rate', $rate);
		$this->assignRef('access', $access);
		$this->assignRef('lists', $lists);
		$this->assignRef('user', $user);
		$this->assignRef('ownuser', $ownuser);
		$this->assignRef('type', $type);
		$this->assignRef('rate_id', $rate_id);

		parent::display($tpl);
	}
}